<template>
	<view class="content">
		<view class="top_div">
			<view class="top_left_div">当前科目:
			<text style="color: #333333; margin-left: 20rpx;">
			{{currCourse}}
			</text></view>
			 <view class="top_right_div" @click="selCourse">
				<image src="../../static/tk_icon_switch_lj.png"></image>
				<text>切换科目</text>
			</view> 
		</view>
		<list class="paper_list">
			<cell class="paper_item" v-for="(item,index) in dataList"
			                          @tap="paperDetail(item.id)">
				<view class="item_left">
					<view class="paper_title">{{item.title}}</view>
					<view class="paper_time">
						<!-- <text>{{item.num}}人做过 </text> -->
						<!-- <text>审核时间:{{item.duration}} </text> -->
						<text>{{item.topicNum }}道题 </text> 
						<text>时长:{{item.duration}} </text> 
					</view>
				</view>
				<view class="item_right">
					 <image src="../../static/ico_arrow_right_red.png"></image>
				</view>
			</cell>
		</list>
		
		
		
		<popCourse v-show="bottomSHow" :courseList="courseList" @courseItemClicks="courseItem"></popCourse>
	</view>
</template>

<script>
	import popCourse from '../../components/course/course.vue';
	export default{
		components: {
			popCourse
		},onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.courseId = uni.getStorageSync('cid');
			this.currCourse=uni.getStorageSync('cname');
			
		},
		data(){
			return{
				bottomSHow: false,//是否显示选择课程
				c: {},
				currCourse:"请选择",//当前课程
				courseList:[],
				dataList:[
					// {"id":1,"title":"阿里云期中模拟测试","num":10,"time":"2021-10-02 20:10:10"},
					// {"id":2,"title":"阿里云期中模拟测试2","num":15,"time":"2021-10-05 20:10:10"}
				]
			}
		},	
		onReady: function() {
			this.initExamList();
			//初始化所有的的课程信息
			uni.request({
				url: this.baseUrl+'getCourseByStuId', //仅为示例，并非真实接口地址。
				method:'POST',
				data: {
					stuId: uni.getStorageSync('uid')
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				},
				success: (res) => {
					this.courseList=res.data.courseEntity;
				}
			});


		},
		methods:{
			courseItem:function(index){
				//点击某个科目
				this.currCourse=this.courseList[index].name;
				this.c.cid=this.courseList[index].id;
				this.c.cname=this.courseList[index].name;
				this.bottomSHow=false;
			},
			selCourse:function(){
				//点击切换科目
				this.bottomSHow=true;
			},
			paperDetail:function(index){
				//试卷详情
				uni.navigateTo({
					url: '../testDetail/testDetail?id='+index
				});
			},
			initExamList:function(){
				uni.request({
					url: this.baseUrl+'getTestPapers', //仅为示例，并非真实接口地址。
					method:'GET',
					data: {
						courseId:this.courseId,
						chapterId:0,
						testMode:1
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					success: (res) => {
						this.dataList=res.data.testPaperList;
						
					},
				});
				
			}
		}
	}
</script>

<style>
	.top_div{
		height: 76rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #FFFFFF;
	}
	.top_div .top_left_div{
		font-size: 22rpx;
		color: #666666;
	}
	
	.top_div .top_right_div image{
		width: 20rpx;
		height: 20rpx;
	}
	.top_div .top_right_div text{
		font-size: 22rpx;
		margin-left: 20rpx;
		color: #e65e4f;
	}
	.paper_list{
		background: #FFFFFF;
	}
	.paper_item{
		display: flex;
		background: #FFFFFF;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #E8E8E8;
	}
	.paper_item .item_left{
		flex: 1;
	}
	.paper_item .item_left .paper_title{
		font-size: 26rpx;
		color: #333333;
	}
	.paper_item .item_left .paper_time{
		font-size: 22rpx;
		margin-top: 30rpx;
		color: #666666;
	}
	.paper_item .item_left .paper_time text:nth-child(1){
		margin-right: 20rpx;
	}
	.paper_item .item_right image{
		width: 18rpx;
		height: 30rpx;
	}
</style>
